package com.controller;

import com.entity.User;
import com.service.UserService;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("login")
    public Object login(@RequestBody User user){
        return userService.login(user);
    }
    @PostMapping("userRegister")
    public Object userRegister(@RequestBody User user){
        return userService.userRegister(user);
    }


    /*
       修改密码
        UserName;用户名
        pwd;旧密码
        newPwd:新密码
    */
    @PostMapping("updateUserPwd")
    public Object updateUserPwd(@RequestBody String data){
        System.out.println(data);
        JSONObject json = JSONObject.fromObject(data);
        String userName =  json.getString("userName");
        String pwd =  json.getString("pwd");
        String newPwd =  json.getString("newPwd");
        return  userService.updateUserPwd(userName,pwd,newPwd);
    }

}
